package com.yjc.rabbitMQ.six;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.yjc.rabbitMQ.utils.RabbitMQUtils;

/**
 * @author shkstart
 * @create 2022-08-02 8:39
 */
public class ReceiveLogsDirect02 {

    private static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {
        System.out.println("ReceiveLogsDirect02接收消息中......");

        Channel channel = RabbitMQUtils.getChannel();
        String queue_name = "console";
        channel.queueDeclare(queue_name, false, false, false, null);
        channel.queueBind(queue_name, EXCHANGE_NAME, "info");
        channel.queueBind(queue_name, EXCHANGE_NAME, "warning");

        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println(new String(message.getBody(), "UTF-8"));
        };

        channel.basicConsume(queue_name, true, deliverCallback, (consumerTag) -> {
            System.out.println("接收消息被取消*(￣▽￣)~");
        });
    }
}
